﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;

public class MoveAni : AniDecorator {

    private Vector3 endValue;
    private float duration;

    public MoveAni(AniDecorator aniDecorator, Vector3 endValue, float duration) : base(aniDecorator) {
        this.endValue = endValue;
        this.duration = duration;
    }

    private Tweener Move(Transform transform) {
       return  transform.DOLocalMove(endValue, duration);
    }

    public override Tweener Play(Transform transform)
    {
       return Move(transform).OnComplete(() =>
        {
            base.Play(transform);
        });
    }

    public override Tweener Rewind(Transform transform)
    {
        Tweener tweener = base.Rewind(transform);
        if (tweener != null)
        {
            tweener.OnComplete(() =>
            {
                Move(transform);
            });
        }
        else {
            Move(transform);
        }
        return tweener;
    }
}
